package ipgather.core.proxy.thread;

import ipgather.entity.Host;

public class SyncStackHost {
	
	private int index = 0;
	private int len = 20;
	private Host[] hosts = new Host[len];
	
	public synchronized void push(final Host host){
		if(len == index){
			try {
				this.wait();//等待其他人执行
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		this.notify();//通知其他人执行
		hosts[index] = host;
		index++;
	}
	
	public synchronized Host pop(){
		if(0 == index){
			try {
				this.wait();//等待其他人执行
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		this.notify();//通知其他人执行
		index--;
		return hosts[index];
	}

}
